package com.cango.qutz.web.util;

import java.io.Serializable;

public class LabelValueBean implements Comparable, Serializable {
    
    private String label;

    private String value;

    public LabelValueBean() {
        super();
    }

    public LabelValueBean(String label, String value) {
        this.label = label;
        this.value = value;
    }

    public String getLabel() {
        return this.label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public int compareTo(Object o) {
        String otherLabel = ((LabelValueBean) o).getLabel();
        return this.getLabel().compareTo(otherLabel);
    }
    
    
    @Override
    public boolean equals(Object obj) {
	if(obj == null) return false;
	if(!(obj instanceof LabelValueBean)) return false;
	LabelValueBean other = (LabelValueBean) obj;
	return this.getValue().equals(other.getValue()) && this.getLabel().equals(other.getLabel());
    }

    @Override
    public int hashCode() {
	int result = 17;
	result = result + (label == null ? 0 : label.hashCode());
	result = result + (value == null ? 0 : value.hashCode());
	return result;
    }

    @Override
    public String toString() {
	return "[label:" + this.getLabel() + ",value:" + this.getValue() + "]";
    }


    private static final long serialVersionUID = 6747548031231985875L;
    
  //{ "label": "Choice1", value: "value1" }
    public String getJsonFormat(){
    	StringBuilder result = new StringBuilder();
    	result.append("{\"label\": \"").append(this.label).append("\", ")
    		.append("\"value\": \"").append(this.value).append("\"}");
    	
    	return result.toString();
    }
}
